package com.xuxueli.applyModules.commont.testEntityFeids;
import net.bytebuddy.implementation.bind.annotation.SuperCall;

import java.math.BigDecimal;
import java.util.concurrent.Callable;

public class BigDecimalInterceptor {
    public static BigDecimal intercept(@SuperCall Callable<BigDecimal> zuper) throws Exception {
        BigDecimal res = zuper.call();
        if(res != null) {
            BigDecimal n = res;
            if (n.unscaledValue().intValue() == 0) {
                return BigDecimal.ZERO;
            }

            if (n.scale() <= 0) {
                return n;
            }

            BigDecimal stripped = n.stripTrailingZeros();
            if (stripped.scale() < 0) {
                stripped = n.setScale(0);
            }
            return stripped;
        }
        return res;
    }
}